/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
import javax.persistence.*;
import jpapractica.*;

public class SongManager {
    
    EntityManagerFactory emf;
    EntityManager managerSong;
    
    public SongManager(){
        EntityManagerFactory emf;
        EntityManager managerSong;
    }
    
    public Song create (int id, String title, float duracion){
        
        Song cancion = new Song(id, title, duracion);
        
        managerSong.getTransaction().begin();
        managerSong.persist(cancion);
        managerSong.getTransaction().commit();
        
        return cancion;
    }
    public void delete(int id){
        Song cancion = managerSong.find(Song.class,id);
        managerSong.getTransaction().begin();
        managerSong.remove(cancion);
        managerSong.getTransaction().commit();
    }
    public void update(int id, String title, float duracion){
        Song cancion = managerSong.find(Song.class,id);
        managerSong.getTransaction().begin();
        cancion.setTitle(title);
        cancion.setDuration(duracion);
        managerSong.getTransaction().commit();
    }    
    
}
